<pw:html>
    <pw:head>
        <title>SISCO - Buscar productos por lote</title>

        <pw:component name="pw_include_view" data-show="true" data-src="head_scripts.html"></pw:component>
    </pw:head>

    <pw:body>

        <pw:component name="pw_include_view" data-show="true" data-src="header.html"></pw:component>

        <div class="container">
            <pw:component name="pw_include_view" data-show="true" data-src="messages.html"></pw:component>
            
            <pw:component name="pw_div" data-show="true" data-class="row" data-id="">
                <pw:container>

                    <pw:component name="pw_div" data-show="true" data-class="span3" data-id="">
                        <pw:container>
                            <pw:component name="pw_include_view" data-show="true" data-src="inventario_sidebar.html"></pw:component>
                        </pw:container>
                    </pw:component>

                    <pw:component name="pw_div" data-show="true" data-class="span9" data-id="">
                        <pw:container>

                            <pw:component name="pw_form" data-show="true" data-class="" data-id="" data-action="" data-enctype="multipart/form-data" data-method="post">
                                <pw:container>
                                    
                                    <pw:component name="pw_text" data-show="true" data-content="Buscar productos por lote" data-tag="legend" data-free=""></pw:component>
									
                                    <pw:component name="pw_div" data-show="true" data-class="row" data-id="">
                        				<pw:container>
                                            
                                            <pw:component name="pw_div" data-show="true" data-class="span4" data-id="">
                                                <pw:container>
                                                    
                                                    <pw:component name='pw_labeled_input' data-name='codigo-producto' data-id='codigo-producto' data-label='Código' data-type='text' data-value='' data-placeholder='EAN-13 o código interno' data-free=''></pw:component>
                                                    <pw:component name='pw_labeled_input' data-name='descripcion' data-id='descripcion' data-label='Descripción' data-type='text' data-value='' data-placeholder='' data-free='style="disabled" disabled="disabled"'></pw:component>
                                                                                                        
                                                </pw:container>
                                            </pw:component> <!-- col1 -->
                                            
                                            <pw:component name="pw_div" data-show="true" data-class="span4 offset1 loteable" data-id="">
                                                <pw:container>
                                                    
                                                    <label for="lotes">Lote</label>
                                                    <select name="lotes" id="lotes">
                                                    </select>
                                                    
                                                </pw:container>
                                            </pw:component> <!-- col2 -->
                                            
                                        </pw:container>
                            		</pw:component> <!-- .row -->
                                    
                                    <pw:component name="pw_div" data-show="true" data-class="form-actions" data-id="">
                                        <pw:container>
                                            <pw:component name="pw_button" data-show="true" data-id="" data-name="" data-caption="Buscar" data-free="class='btn btn-primary btn-busqueda'" data-type="submit"></pw:component>
                                        </pw:container>
                                    </pw:component> <!-- .form-actions -->
                                    
                                </pw:container>
                            </pw:component> <!-- form -->

                        </pw:container>
                    </pw:component> <!-- .span9 -->

                </pw:container>
            </pw:component> <!-- .row -->

            <pw:component name="pw_include_view" data-show="true" data-src="footer.html"></pw:component>

        </div><!-- .container -->

        <pw:component name="pw_include_view" data-show="true" data-src="footer_scripts.html"></pw:component>
        
        <script>
            
            function desactivarBusqueda() {
                jQuery('.btn-busqueda').attr('disabled','disabled');    
            }
            
            function activarBusqueda() {
                jQuery('.btn-busqueda').removeAttr('disabled');    
            }
            
            jQuery('#codigo-producto').on('change',function(e) {
                jQuery.ajax({
                    url: 'productos/detalle/'+jQuery('#codigo-producto').val(),
                    type: 'GET',
                    dataType: 'JSON',
                    success: function(data){
                        if (data.id) {
                            jQuery('#descripcion').val(data.descripcion);
                            if (data.loteable == "1") {
                                jQuery('#lotes').empty();
                                $(data.lotes).each( function() {
                                    var $option = $("<option />");
                                    $option.attr("value", this.id).text(this.codigo);
                                    jQuery('#lotes').append($option);
                                });
                                jQuery('.loteable').show();
                            }
                            else {
                                jQuery('.loteable').hide();
                            }
                            activarBusqueda();
                        }
                        else {
                            jQuery('#descripcion').val('ERROR');
                            jQuery('.loteable').hide();
                        }
                    },
                    error: function(a,b,c){
                        alert('ERROR');
                    }
                    
                });
            });
        </script>
    </pw:body>
</pw:html>